import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/page/home/item/tender_list_cell.dart';
import 'package:tender_flutter/page/home/model/certification_entity.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/widgets/text_highlight.dart';

class CertificateListCell extends StatefulWidget {
  const CertificateListCell(
      {Key key, this.data, this.onTap, this.onCollection, this.keyword})
      : super(key: key);

  final String keyword;
  final CertificationEntity data;
  final GestureTapCallback onTap;
  final CollectionCallback onCollection;

  @override
  _CertificateListCellState createState() => _CertificateListCellState();
}

class _CertificateListCellState extends State<CertificateListCell> {
  @override
  Widget build(BuildContext context) {
    return _initCell();
  }

  Widget _initCell() {
    return GestureDetector(
        onTap: widget.onTap,
        child: Container(
          color: ThemeColors.colorWhite,
          padding: EdgeInsets.symmetric(
              horizontal: ScreenAdapter.width(30),
              vertical: ScreenAdapter.height(20)),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Row(
                children: <Widget>[
                  Container(
                    width: ScreenAdapter.width(50),
                    height: ScreenAdapter.width(50),
                    margin: EdgeInsets.only(right: ScreenAdapter.width(18)),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: ThemeColors.colorType6,
                        borderRadius:
                            BorderRadius.circular(ScreenAdapter.width(8))),
                    child: Text("资",
                        style: TextStyle(
                            color: ThemeColors.colorWhite,
                            fontSize: ScreenAdapter.sp(30),
                            fontWeight: FontWeight.bold)),
                  ),
                  Expanded(
                      child: TextHighlight(
                    content: widget.data.Name ?? "-",
                    keyWords: [widget.keyword],
                    normalStyle: TextStyle(
                        color: ThemeColors.colorType1,
                        fontSize: ScreenAdapter.sp(30),
                        fontWeight: FontWeight.w500),
                    highlightStyle: TextStyle(
                        color: ThemeColors.colorType56,
                        fontSize: ScreenAdapter.sp(30),
                        fontWeight: FontWeight.w500),
                  )),
                  GestureDetector(
                      onTap: () async {
                        widget.onCollection().then((value) => {
                              /// 请求成功改变状态
                              if (value)
                                {
                                  setState(() {
                                    widget.data.isFocus = !widget.data.isFocus;
                                  })
                                }
                            });
                      },
                      child: Image.asset(
                        RPath.imgPath +
                            (widget.data.isFocus
                                ? "icon_favorites_select.png"
                                : "icon_favorites_normal.png"),
                        width: ScreenAdapter.width(35),
                        height: ScreenAdapter.width(35),
                      ))
                ],
              ),
              // SizedBox(height: ScreenAdapter.height(15)),
              Padding(
                  padding: EdgeInsets.only(top: ScreenAdapter.width(25)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                          child: Text(
                        "注册企业：" + widget.data.CompanyName ?? "-",
                        maxLines: 1,
                        softWrap: true,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                            color: ThemeColors.colorType7,
                            fontSize: ScreenAdapter.sp(26)),
                      )),
                      Text(
                        widget.data.StartDate,
                        style: TextStyle(
                            color: ThemeColors.colorType7,
                            fontSize: ScreenAdapter.sp(26)),
                      )
                    ],
                  ))
            ],
          ),
        ));
  }
}
